package com.mybatiscore.jiaocheng.d07mybatis_分页查询;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatiscore.Mapper.TRoleMapper;
import com.mybatiscore.POJO.TRole;
import com.mybatiscore.Util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class d02pagehelper {
    @Test
    public void test(){

        SqlSession sqlSession = SqlSessionUtil.openSession();
        TRoleMapper mapper = sqlSession.getMapper(TRoleMapper.class);

        //在查询语句前开启分页
        PageHelper.startPage(3,8);

        List<TRole> tRoles = mapper.selectAll();
        System.out.println(tRoles.toString());


        sqlSession.close();
    }

    //PageInfo
    @Test
    public void test1(){

        SqlSession sqlSession = SqlSessionUtil.openSession();
        TRoleMapper mapper = sqlSession.getMapper(TRoleMapper.class);

        //在查询语句前开启分页
        PageHelper.startPage(3,8);

        List<TRole> tRoles = mapper.selectAll();
        PageInfo<TRole> tRolePageInfo = new PageInfo<>(tRoles,3);
        System.out.println(tRolePageInfo);
        /*
            PageInfo{pageNum=3, pageSize=8, size=8, startRow=17, endRow=24, total=48, pages=6, list=Page{count=true, pageNum=3, pageSize=8, startRow=16, endRow=24, total=48, pages=6, reasonable=false, pageSizeZero=false}[TRole{id=47, name='组长', userId=null}, TRole{id=48, name='测试员', userId=null}, TRole{id=49, name='项目经理', userId=17}, TRole{id=50, name='技术总监', userId=17}, TRole{id=51, name='java软件工程师', userId=17}, TRole{id=52, name='CEO', userId=18}, TRole{id=53, name='组长', userId=18}, TRole{id=54, name='测试员', userId=18}],
            prePage=2, nextPage=4, isFirstPage=false, isLastPage=false, hasPreviousPage=true, hasNextPage=true, navigatePages=3, navigateFirstPage=2, navigateLastPage=4, navigatepageNums=[2, 3, 4]}

         */


        sqlSession.close();
    }
}
